﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;

namespace OperateMouse
{
    /// <summary>
    /// 自动执行
    /// </summary>
    internal static class AutoExecute
    {
        /// <summary>
        /// 配置
        /// </summary>
        public static SysConfig Config { get; set; }
        /// <summary>
        /// 锁
        /// </summary>
        private static object _lock = new object();
        static AutoExecute()
        {
            string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "config.db");
            if (File.Exists(path))
            {
                string json = File.ReadAllText(path);
                Config = JsonSerializer.Deserialize<SysConfig>(json)!;
            }
            else
            {
                Config = new SysConfig();
            }
        }
        /// <summary>
        /// 保存配置
        /// </summary>
        public static void Save() 
        {
            lock (_lock)
            {
                string path = Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, "config.db");
                string text = JsonSerializer.Serialize(Config);
                File.WriteAllText(path,text);
            }
        }
    }
}
